package org.example.protocol;

import org.artifact.core.lang.DTO;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import org.example.protocol.structs.*;

public class StructUtil {
    static Map<Integer, Supplier<? extends  DTO>> cahce = new HashMap<>();
    static Map<Class, Integer> codes = new HashMap<>();
    static {
        // 玩家简单信息
        cahce.put(1102355472,() -> new PlayerInfoDTO());
        // 玩家信息
        cahce.put(131897118,() -> new PlayerDTO());

        // 玩家简单信息
        codes.put(org.example.protocol.structs.PlayerInfoDTO.class,1102355472);
        // 玩家信息
        codes.put(org.example.protocol.structs.PlayerDTO.class,131897118);
    }

    public static <T extends DTO> T create(int code){
        return (T) cahce.get(code).get();
    }

    public static Integer structCode(Class structClass){
        return codes.get(structClass);
    }
}
